home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Caml Light 0.61 / Source / src / lib / fchar.ml < prev    next >
Encoding:
Text File  |  1993-09-24  |  596 b   |  23 lines  |  [TEXT/MPS ]

  1. (* Character operations, without sanity checks *)
  2.  
  3. #open "int";;
  4. #open "fstring";;
  5.  
  6. let char_for_read = function
  7.     `\`` -> "\\`"
  8.   | `\\` -> "\\\\"
  9.   | `\n` -> "\\n"
  10.   | `\t` -> "\\t"
  11.   | c ->  if is_printable c then
  12.             make_string 1 c
  13.           else begin
  14.             let n = int_of_char c in
  15.             let s = create_string 4 in
  16.             set_nth_char s 0 `\\`;
  17.             set_nth_char s 1 (char_of_int (48 + n / 100));
  18.             set_nth_char s 2 (char_of_int (48 + (n / 10) mod 10));
  19.             set_nth_char s 3 (char_of_int (48 + n mod 10));
  20.             s
  21.           end
  22. ;;
  23.